package com.ruoyi.business.controller;

import com.ruoyi.business.domain.BusinessComponent;
import com.ruoyi.business.domain.BusinessComponentComposite;
import com.ruoyi.business.service.IBusinessComponentService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.EnterpriseAndApplicationCodeProperty;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 业务组件Controller
 *
 * @author ruoyi
 * @date 2025-09-04
 */
@RestController
@RequestMapping("/businessComponent")
public class BusinessComponentController extends BaseController
{
    @Autowired
    private IBusinessComponentService businessComponentService;

    /**
     * 查询业务组件列表
     */
    @RequiresPermissions("business:businessComponent:list")
    @GetMapping("/list")
    public TableDataInfo list(BusinessComponent businessComponent)
    {
        startPage();
        List<BusinessComponent> list = businessComponentService.selectBusinessComponentList(businessComponent);
        return getDataTable(list);
    }

    /**
     * 导出业务组件列表
     */
    @RequiresPermissions("business:businessComponent:export")
    @Log(title = "业务组件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessComponent businessComponent)
    {
        List<BusinessComponent> list = businessComponentService.selectBusinessComponentList(businessComponent);
        ExcelUtil<BusinessComponent> util = new ExcelUtil<BusinessComponent>(BusinessComponent.class);
        util.exportExcel(response, list, "业务组件数据");
    }

    /**
     * 获取业务组件详细信息
     */
    @RequiresPermissions("business:businessComponent:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(businessComponentService.selectBusinessComponentById(id));
    }

    /**
     * 新增业务组件
     */
    @RequiresPermissions("business:businessComponent:add")
    @Log(title = "业务组件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@EnterpriseAndApplicationCodeProperty BusinessComponent businessComponent)
    {
        return toAjax(businessComponentService.insertBusinessComponent(businessComponent));
    }

    /**
     * 修改业务组件
     */
    @RequiresPermissions("business:businessComponent:edit")
    @Log(title = "业务组件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@EnterpriseAndApplicationCodeProperty BusinessComponent businessComponent)
    {
        return toAjax(businessComponentService.updateBusinessComponent(businessComponent));
    }

    /**
     * 删除业务组件
     */
    @RequiresPermissions("business:businessComponent:remove")
    @Log(title = "业务组件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessComponentService.deleteBusinessComponentByIds(ids));
    }
    /**
     * 提交新增业务组件
     */
    @RequiresPermissions("business:businessComponent:commitadd")
    @Log(title = "业务组件", businessType = BusinessType.INSERT)
    @PostMapping("/commitadd")
    public AjaxResult commitAdd(@RequestBody BusinessComponentComposite businessComponentComposite)
    {
        return AjaxResult.success(businessComponentService.commitAdd(businessComponentComposite));
    }
    /**
     * 提交更新业务组件
     */
    @RequiresPermissions("business:businessComponent:commitupdate")
    @Log(title = "业务组件功能点主表", businessType = BusinessType.UPDATE)
    @PostMapping("/commitupdate")
    public AjaxResult commitUpdate(@RequestBody BusinessComponentComposite businessComponentComposite)
    {
        return AjaxResult.success(businessComponentService.commitUpdate(businessComponentComposite));
    }
    /**
     * 新增草稿业务组件
     */
    @RequiresPermissions("business:businessComponent:adddraft")
    @Log(title = "业务组件", businessType = BusinessType.INSERT)
    @PostMapping("/draftadd")
    public AjaxResult draftAdd(@RequestBody BusinessComponentComposite businessComponentComposite)
    {
        return AjaxResult.success(businessComponentService.insertBusinessComponentComposite(businessComponentComposite));
    }
    /**
     * 更新草稿业务组件
     */
    @RequiresPermissions("business:tenantFunctionMain:updatedraft")
    @Log(title = "业务组件功", businessType = BusinessType.UPDATE)
    @PostMapping("/draftupdate")
    public AjaxResult draftUpdate(@RequestBody BusinessComponentComposite businessComponentComposite)
    {
        return AjaxResult.success(businessComponentService.updateBusinessComponentComposite(businessComponentComposite));
    }
}
